package com.example.springboot.mapper;

import com.example.springboot.entity.Application;
import com.example.springboot.entity.Instore;
import com.example.springboot.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Select("SELECT * from sys_order")
    List<Order> findAll();

    @Insert("insert into sys_order(purchaser_id,purchase_date,is_approve,approval_id,note) " +
            "VALUES (#{purchaserId},#{purchaseDate},#{isApprove},#{approvalId},#{note});")
    int insert(Order order);

    int update(Order order);

    @Select("SELECT max(id) from sys_order;")
        //查询最新增加的采购申请单的id
    Integer findLatest();

    @Select("SELECT * from sys_order where purchaser_id = #{purchaserId}")
    List<Order> findByUser(Integer purchaserId);

    @Select("select * from sys_order where is_approve like concat('%',#{isApprove},'%') limit #{pageNum},#{pageSize}")
    List<Order> selectPage(Integer pageNum, Integer pageSize, String isApprove);

    @Select("select count(*) from sys_order where is_approve like concat('%',#{isApprove},'%')")
    Integer selectTotal(String isApprove);

    @Update("update sys_order set is_approve = '已审批' where id= #{id}")
    int updateApprove(@Param("id")Integer id);

    @Update("update sys_order set approval_id = #{approvalId} where id= #{id}")
    int updateApproval(Integer id, Integer approvalId);

}